package io.renren.modules.comment.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.comment.entity.UserCommentEntity;
import io.renren.modules.comment.service.UserCommentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author starry
 * @email starry@stu.hnucm.edu.cn
 * @date 2022-12-18 12:54:15
 */
@RestController
@RequestMapping("comment/usercomment")
@Api(tags = "用户评论Api")
public class UserCommentController {
    @Autowired
    private UserCommentService userCommentService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
//    @RequiresPermissions("comment:usercomment:list")
    @ApiOperation("评论列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userCommentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.GET)
//    @RequiresPermissions("comment:usercomment:info")
    @ApiOperation("评论列表By id")
    public R info(@PathVariable("id") Integer id){
		UserCommentEntity userComment = userCommentService.getById(id);

        return R.ok().put("userComment", userComment);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
//    @RequiresPermissions("comment:usercomment:save")
    @ApiOperation("新增评论")
    public R save(@RequestBody UserCommentEntity userComment){
		userCommentService.save(userComment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
//    @RequiresPermissions("comment:usercomment:update")
    @ApiOperation("修改评论")
    public R update(@RequestBody UserCommentEntity userComment){
		userCommentService.updateById(userComment);

        return R.ok();
    }

    /**
     * 通过评论id修改评论的点赞信息
     * 用户点赞接口
     */



    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
//    @RequiresPermissions("comment:usercomment:delete")
    @ApiOperation("删除评论")
    public R delete(@RequestBody Integer[] ids){
		userCommentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 通过汽车编号查询用户评论
     */
    @RequestMapping(value = "/byCarIdList/{car_id}",method = RequestMethod.GET)
    @ApiOperation("评论列表By car_id")
    @ResponseBody
    public R findByCarId(@PathVariable("car_id")Integer carId){
       List<UserCommentEntity> userCommentList = userCommentService.findByCarId(carId);
       return R.ok().put("userCommentList", userCommentList);
    }

}
